@extends('layouts.master')

@section('style')
    <style>
        .layui-field-box {
            padding: 0;
        }

        .layui-field-box .layui-form.layui-border-box.layui-table-view {
            margin-bottom: 0;
            margin-top: 15px;
        }
    </style>
@stop
@section('content')
    <div class="layui-row">
        <fieldset class="layui-elem-field">
            <legend>月上生活馆-顾客列表(暂不支持)</legend>
            <div class="layui-field-box">
                <table id="customers" lay-filter="customers"></table>
            </div>
        </fieldset>
    </div>
    <div class="layui-row">
        <fieldset class="layui-elem-field">
            <legend>月上生活馆-客服列表</legend>
            <div class="layui-field-box">
                <table id="users" lay-filter="users"></table>
            </div>
        </fieldset>
    </div>
@stop

@section('script')
    <script type="text/html" id="userTools">
{{--        <span class="layui-btn layui-btn-xs" lay-event="chat">聊天</span>--}}
    </script>
    <script>
        layui.use(['table'], function () {
            let table = layui.table;

            table.render({
                elem: '#customers'
                , url: '{{ route('home.customers') }}'
                , page: true
                , cols: [[
                    {field: 'id', title: 'ID', width: 80}
                    , {field: 'username', title: '用户名'}
                    , {field: 'mobile', title: '手机号'}
                    , {field: 'email', title: '邮箱'}
                    , {
                        field: 'group_name', title: '会员等级', templet: function (v) {
                            return "<span class='layui-btn layui-btn-xs'>" + v.group.name + "</span>"
                        }
                    }
                    , {
                        field: 'status', title: '状态', templet: function (v) {
                            return v.status === 1
                                ? "<span class='layui-btn layui-btn-xs'>正常</span>"
                                : "<span class='layui-btn layui-btn-xs layui-btn-danger'>禁用</span>"
                        }
                    }
                    , {field: 'created_at', title: '注册时间'}
                ]]
                , parseData: function (r) {
                    return {
                        code: 0
                        , msg: 'ok'
                        , data: r.data
                        , count: r.total
                    };
                }
            });


            table.render({
                elem: '#users'
                , url: '{{ route('home.users') }}'
                , page: true
                , cols: [[
                    {field: 'id', title: 'ID', width: 80}
                    , {field: 'name', title: '用户名'}
                    , {field: 'email', title: '邮箱'}
                    , {field: 'created_at', title: '注册时间'}
                    , {fixed: 'right', title: '操作', width: 150, align: 'center', toolbar: '#userTools'}
                ]]
                , parseData: function (r) {
                    return {
                        code: 0
                        , msg: 'ok'
                        , data: r.data
                        , count: r.total
                    };
                }
            });

        });
    </script>
@stop
